package tools;

public class DoubleMatrix extends Matrix<Double> {

	public DoubleMatrix(int ln, int cl) {
		super(ln, cl);
		mtx = new Double[ln][cl];
	}
	
	public DoubleMatrix(Vector<Double> a, Vector<Double> b){
		super(a.getDim(), b.getDim());
		mtx = new Double[ln][cl];
		for(int i = 0; i < ln; i++){
			for(int j = 0; j < cl; j++){
				set(i, j, a.get(i)*b.get(j));
			}
		}
	}

	@Override
	protected Double define0() {
		return 0.0;
	}

	@Override
	protected Double defineSum(Double elem1, Double elem2) {
		return elem1 + elem2;
	}

	@Override
	protected Double defineProduct(Double elem1, Double elem2) {
		return elem1*elem2;
	}

	@Override
	protected Double defineSub(Double elem1, Double elem2) {
		return elem1 - elem2;
	}

	@Override
	public Vector<Double> getLine(int i) {
		Vector<Double> vec = new DoubleVector(cl);
		for(int j = 0; j < cl; j++) vec.set(j, get(i,j));
		return vec;
	}

	@Override
	public Vector<Double> getColumn(int i) {
		Vector<Double> vec = new DoubleVector(ln);
		for(int j = 0; j < ln; j++) vec.set(j, get(j,i));
		return vec;	
	}

	@Override
	public Matrix<Double> copy() {
		Matrix<Double> cp = new DoubleMatrix(ln, cl);
		for(int i = 0; i < ln; i++){
			for(int j = 0; j < cl; j++){
				cp.set(i, j, get(i,j));
			}
		}
		return cp;
	}

	@Override
	public Matrix<Double> transposition() {
		Matrix<Double> cp = new DoubleMatrix(cl, ln);
		for(int i = 0; i < ln; i++){
			for(int j = 0; j < cl; j++){
				cp.set(i, j, get(j,i));
			}
		}
		return cp;
	}

}
